<?php
/**
 * 商机跟进
 * @Author: wjf
 * @Date: 2022-12-01 18:22:40
 */

namespace app\crm\controller\commercial;

use app\crm\model\commercial\Clfollow as CommercialClfollow;
use think\Controller;
use think\facade\Session;

class Clfollow extends Controller
{
    /**
     * 主页面
     * @Author: wjf
     * @Date: 2022-12-01 09:16:16
     */    
    public function index()
    {
        return $this->fetch();
    }
    
     /**
     * 遍历数据
     * @Author: wjf
     * @Date: 2022-12-03 10:54:15
     */    
    public function list()
    {
        if ($this->request->param('data')) {
            $aa = $this->request->get('data');
            $arr = [];
            foreach ($aa as $k => $v) {
                if (!$v) {
                    unset($aa[$k]);
                } else {
                    $k = 'crm_classify_follow.' . $k;
                    $arr[$k] = $v;
                }
            }
            $page = ($_GET['page'] - 1) * $_GET['limit'];
            $data = CommercialClfollow::withJoin('Ourclients')->where($arr)->limit($page, $_GET['limit'])->where('crm_classify_follow.classify',2)->select();
            $count = CommercialClfollow::withJoin('Ourclients')->where('classify_id', Session::get('f_id'))->where('crm_classify_follow.classify',2)->count(); 
            return json(['code' => 0, 'msg' => '遍历', 'count' => $count, 'data' => $data]);
        }
    }

    /**
     * 全部客户跟进记录
     * @Author: wjf
     * @Date: 2022-12-06 11:37:40
     */    
    public function lists()
    {
        $page = ($_GET['page'] - 1) * $_GET['limit'];
        $data = CommercialClfollow::with('Cllist')->limit($page, $_GET['limit'])->where('crm_classify_follow.classify',2)->select();
        $count = CommercialClfollow::with('cllist')->where('crm_classify_follow.classify',2)->count();
        return json(['code' => 0, 'msg' => '遍历', 'count' => $count, 'data' => $data]);
    }
}
